import json
import urllib
import uuid

from selenium import webdriver;
from selenium.webdriver import ActionChains
import time;
import requests

print(time.localtime(time.time() + 60 * 60 * 24 * 90))
print(uuid.uuid4())
uid = str(uuid.uuid4())
startTime = time.strftime("%Y-%m-%d", time.localtime())
endtime = time.localtime(time.time() + 60 * 60 * 24 * 90)
endtime = time.strftime("%Y-%m-%d", endtime)
operation = "WINDOWS"
mac = "B4:96:91:61:D3:FA;00:15:5D:2D:10:06;DC:71:96:11:93:33;DC:71:96:11:93:34;DE:71:96:11:93:33;E4:54:E8:8D:40:8A;00:50:56:C0:00:01;00:50:56:C0:00:08;DC:71:96:11:93:37"
requestBody = {"__version__": "2.0",
               "__sys__": {"name": "", "descName": "", "msg": "", "msgKey": "", "detailMsg": "", "status": 0,
                           "traceId": ""},
               "__blocks__": {"main": {"attr": {}, "meta": {"desc": "", "attr": {},
                                                            "columns": [{"pos": 0, "name": "projectOrContract"},
                                                                        {"pos": 1, "name": "projectName"},
                                                                        {"pos": 2, "name": "templateDeptName"},
                                                                        {"pos": 3, "name": "templateName"},
                                                                        {"pos": 4, "name": "templateCode"},
                                                                        {"pos": 5, "name": "rows"},
                                                                        {"pos": 6, "name": "columns"},
                                                                        {"pos": 7, "name": "remark5"},
                                                                        {"pos": 8, "name": "customeCompany"},
                                                                        {"pos": 9, "name": "remark4"},
                                                                        {"pos": 10, "name": "customeDept"},
                                                                        {"pos": 11, "name": "customeEmail"},
                                                                        {"pos": 12, "name": "customePosition"},
                                                                        {"pos": 13, "name": "remark2"},
                                                                        {"pos": 14, "name": "remark1"},
                                                                        {"pos": 15, "name": "customeContact"},
                                                                        {"pos": 16, "name": "recCreatorName"},
                                                                        {"pos": 17, "name": "createrDept"},
                                                                        {"pos": 18, "name": "createrContact"},
                                                                        {"pos": 19, "name": "rowguid"},
                                                                        {"pos": 20, "name": "projectNo"},
                                                                        {"pos": 21, "name": "remark3"},
                                                                        {"pos": 22, "name": "approveStatus"},
                                                                        {"pos": 23, "name": "remark"},
                                                                        {"pos": 24, "name": "submitor"},
                                                                        {"pos": 25, "name": "submitorName"},
                                                                        {"pos": 26, "name": "submitTime"},
                                                                        {"pos": 27, "name": "approver"},
                                                                        {"pos": 28, "name": "approverName"},
                                                                        {"pos": 29, "name": "approveTime"},
                                                                        {"pos": 30, "name": "approveRemark"},
                                                                        {"pos": 31, "name": "wfId"},
                                                                        {"pos": 32, "name": "status"},
                                                                        {"pos": 33, "name": "licenseNo"},
                                                                        {"pos": 34, "name": "createrDeptId"},
                                                                        {"pos": 35, "name": "remark6"},
                                                                        {"pos": 36, "name": "remark7"},
                                                                        {"pos": 37, "name": "remark8"},
                                                                        {"pos": 38, "name": "remark9"},
                                                                        {"pos": 39, "name": "remark10"},
                                                                        {"pos": 40, "name": "remark11"},
                                                                        {"pos": 41, "name": "remark12"},
                                                                        {"pos": 42, "name": "recCreateTime"},
                                                                        {"pos": 43, "name": "recCreator"},
                                                                        {"pos": 44, "name": "archiveFlag"},
                                                                        {"pos": 45, "name": "archiveStampNo"},
                                                                        {"pos": 46, "name": "archiveTime"},
                                                                        {"pos": 47, "name": "companyCode"},
                                                                        {"pos": 48, "name": "accountSet"}]},
                                       "rows": [
                                           ["tmp", "1", "", "iHyperDB-202002",
                                            "1f88b6c7-526d-4b91-9919-15cfb71aa35e", "", "", "1", "1", "1", "1",
                                            "195277@baosight.com", "", "宝信企业高性能实时数据库软件", "iHyperDB", "", "", "",
                                            "18362905003", "", "", "", " ", "", "", "",
                                            "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                                            "", "", "", "", ""]]},
                              "slave": {"attr": {}, "meta": {"desc": "", "attr": {},
                                                             "columns": [{"pos": 0, "name": "AuthorizedProject"},
                                                                         {"pos": 1, "name": "AuthorizedClient"},
                                                                         {"pos": 2, "name": "VersionNumber"},
                                                                         {"pos": 3, "name": "StartDate"},
                                                                         {"pos": 4, "name": "ExpiringDate"},
                                                                         {"pos": 5, "name": "HostMAC"},
                                                                         {"pos": 6, "name": "VCODE"},
                                                                         {"pos": 7, "name": "TagNumber"},
                                                                         {"pos": 8, "name": "ClientNumber"},
                                                                         {"pos": 9, "name": "AuthorizedOS"},
                                                                         {"pos": 10, "name": "LicVersion"},
                                                                         {"pos": 11, "name": "LicenseMode"},
                                                                         {"pos": 12, "name": "AuthorizingCompany"},
                                                                         {"pos": 13, "name": "SupportSPC"},
                                                                         {"pos": 14, "name": "SupportZT"},
                                                                         {"pos": 15, "name": "note"}]}, "rows": [
                                  ["1", "1", "3.6.1", "2021-09-02", "2021-12-02", "00:50:56:98:cd:e3", "", "9999",
                                   "200", "LINUX",
                                   "5.0", "CheckHost", "上海宝信软件股份有限公司", "1", "1", ""]]}}}
requestBody["__blocks__"]["main"]["rows"][0][4] = uid;

requestBody["__blocks__"]["slave"]["rows"][0][3] = startTime;
requestBody["__blocks__"]["slave"]["rows"][0][4] = endtime;
requestBody["__blocks__"]["slave"]["rows"][0][9] = operation;
requestBody["__blocks__"]["slave"]["rows"][0][5] = mac;
import requests
#
# {
#     "饼图卡片的数据结构": {
#         "pie": {
#             "series": [{
#                 "name": "PY",
#                 "value": 9999
#             }, {
#                 "name": "QL",
#                 "value": 9999
#             }]
#         },
#         "useCount": 100,
#         "unusedCount": 20
#     },
#     "曲线图的数据结构": {
#         "data": [{
#             "name": "succese",
#             "value": [{
#                 "time": "1999-01-01",
#                 "value": 999
#             }]
#         }]
#     },
#     "柱状图的数据结构": {
#         "data": [{
#             "name": "bar",
#             "value": [{
#                 "rank": 1,
#                 "value": 999119111
#             }]
#         }]
#     },
#     "排行榜的数据结构": {
#         "data": [{
#             "name": "1",
#             "type": "x",
#             "value": "99.99"
#         }]
#     }
# }
#
# {
#     "ruleInfo": {
#         "ruleId": "93cef27ab13d4ceba6673263cc5a1742",
#         "name": "11111",
#         "desc": "嘻嘻哈哈",
#         "ruleType": "QL",
#         "createTime": 1111111111,
#         "maxSpentTime": 1,
#         "minSpentTime": 1,
#         "avgSpentTime": 1,
#         "successCount": 1,
#         "failCount": 1
#     },
#     "ruleScatter": {
#         "data": [{
#             "count": 666,
#             "time": "1999-01-01",
#             "status": 0
#         }]
#     },
#     "ruleRadar": {
#         "efficient": 1,  # 效率
#         "complexity": 1,  # 复杂度
#         "quality": 1,  # quality
#         "heat": 1,  # 热度
#         "frequency": 1,  # 频率
#     },
#     "ruleRecords": {
#         "data":[{
#             #规则历史执行记录查询
#         }]
#     }
# }
url = "http://bsms.baogang.info/kp/service/KSCP0101/insertLicence"
data = str(requestBody)
# 字符串格式
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cookie': 'a'
}
print(data)
headers[
    'Cookie'] = 'iplat.sessionId=IPLAT-6706983263294FFBA5F4BE86D68FF3F7; iplat.theme=ant; JSESSIONID=00003w81uobW5V6oOLt2dNk9Pip:-1';
requset = urllib.request.Request(url=url, headers=headers, data=data.encode('utf-8'))
res = urllib.request.urlopen(requset)
print(res)
print(res.read().decode('utf-8'))
response = json.dumps(res.read().decode('utf-8'))
licName = response["__blocks__"]["main"]["rows"][0][19]
# print(requestBody)
